<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//echo 'hello options.php'
//settings_fields( 'myoption-group' );
include 'background_list.class.php';

/**
 * Handle an Image upload for the background image.
 *
 * @since 3.0.0
 */
function handle_upload() {
    if (empty($_FILES))
        return;
    check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
    $overrides = array('test_form' => false);
    $file = wp_handle_upload($_FILES['import'], $overrides);
    if (isset($file['error']))
        wp_die($file['error']);
    $url = $file['url'];
    $type = $file['type'];
    $file = $file['file'];
    $filename = basename($file);

    rename($file, get_theme_root() . '/build/images/bg/' . $filename);
}

handle_upload();

$backgroundTable = new background_list();
$backgroundTable->prepare_items();
?>
<div class="wrap">
    <div id="icon-options-general" class="icon32"><br></div>
    <h2>Tło strony</h2>

    <p>Jest to lista wszystkich dostępnych plików tła które zostały dodane przez użytkownika. Są one wyświetlane na wszystkich podstronach z efektem płynnego przejścia z jednego w drugie.</p>
    <p style="color:red">Tło powinno być w rozdzielczości 1920x1280</p>

    <h3>Lista obrazów tła</h3>
    <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
    <form id="movies-filter" method="get">
        <!-- For plugins, we also need to ensure that the form posts back to our current page -->
        <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
        <!-- Now we can render the completed list table -->
        <?php $backgroundTable->display() ?>
    </form>

    <h3>Dodaj nowe tło</h3>
    <table class="form-table">
        <tbody>
            <tr valign="top">
                <th scope="row"><?php _e('Upload Image'); ?></th>
                <td><form enctype="multipart/form-data" id="upload-form" method="post" action="">
                        <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" />
                        <input type="hidden" name="action" value="save" />
                        <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?>
                        <?php submit_button(__('Upload'), 'button', 'submit', false); ?>
                    </form>
                </td>
            </tr>
        </tbody>
    </table>
</div>
